home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n08.arc / EDITDEMO.C next >
Text File  |  1990-03-30  |  2KB  |  60 lines

  1. /*
  2.     EDITDEMO.C      Simple test program demonstrating use of
  3.                     DosEditName and DosCopy APIs in OS/2 1.2
  4.  
  5.     Copyright (C) 1989 Ziff-Davis Communications
  6.     PC Magazine * Ray Duncan
  7.  
  8.     Compile:    cl /Zi /F 2000 editdemo.c
  9.                 markexe lfns testedit.exe
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14.  
  15. #define MAXPATHNAME  260
  16.  
  17. #define API unsigned extern far pascal  // OS/2 API function prototypes 
  18.  
  19. API DosCopy(char far *, char far *, unsigned, unsigned long);
  20. API DosEditName(unsigned, char far *, char far *, char far *, unsigned);
  21.  
  22. FILE *datafile;
  23.  
  24. main(int argc, char *argv[])
  25. {
  26.     char filename[MAXPATHNAME];             // name of original file
  27.     char tempname[MAXPATHNAME];             // name of temporary file
  28.     char backname[MAXPATHNAME];             // name of backup file
  29.  
  30.     strcpy(filename, "arbitrary.file.dat"); // the actual test name
  31.  
  32.     DosEditName(1,                          // edit type (always 1)
  33.                 filename,                   // original file name
  34.                 "*.*.$$$",                  // editing string
  35.                 tempname,                   // receives temporary file name
  36.                 sizeof(tempname));          // max size of edited name
  37.  
  38.     DosEditName(1,                          // edit type (always 1)
  39.                 filename,                   // original file name
  40.                 "*.*.bak",                  // editing string
  41.                 backname,                   // receives backup file name
  42.                 sizeof(backname));          // max size of edited name
  43.  
  44.     DosCopy(filename,                       // name of existing file
  45.             tempname,                       // name of new file
  46.             1,                              // mode (create or replace)
  47.             0L);                            // reserved parameter
  48.  
  49.     datafile = fopen(tempname, "r+");       // open temporary file 
  50.  
  51.                                             // perform modifications
  52.                                             // to temporary file here...
  53.  
  54.     fclose(datafile);                       // close temporary file
  55.  
  56.     unlink(backname);                       // get rid of previous backup
  57.     rename(filename, backname);             // rename original file to .BAK
  58.     rename(tempname, filename);             // assign original file name
  59. }                                           // to temporary file
  60.